#include "UI_h/chatui.h"
#include "ui_chatui.h"
#include "../Entity_h/user.h"
#include "Net_h/NetServerConfig.h"
#include <QDebug>

ChatUI::ChatUI(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ChatUI)
{
    ui->setupUi(this);
    _curUser = new User();
    _curUser->SetFilePath("E:\\nihao.raw");
    //_curUser中_userSocket接收到的数据逐级向上抛出到UI层
    connect(_curUser,SIGNAL(InformUI()),this,SLOT(ShowNewMessage()));
}

ChatUI::~ChatUI()
{
    delete ui;

}

void ChatUI::ShowNewMessage() const{
    ui->textShow->append(_curUser->GetMessage());
}

void ChatUI::on_pushButtonSend_clicked()
{

    QString content = ui->textData->toPlainText();
    _curUser->SendMessage(content);
    ui->textData->clear();

}

void ChatUI::on_pushButtonConnect_clicked()
{
    //从配置类中读取服务器IP和port
    QString ip = NetServerConfig::GetInstance()->GetServerIp();
    QString port = NetServerConfig::GetInstance()->GetServerPort();

    _curUser->SetServer(ip,port);
    _curUser->ConnectServer();
}

void ChatUI::on_pushButtonRecord_clicked()
{
    _curUser->Record();
}

void ChatUI::on_pushButtonFinish_clicked()
{
    _curUser->Finish();
}

void ChatUI::on_pushButtonPlay_clicked()
{
    _curUser->Play();
}
